package cn.wolfcode.web.controller.business;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.wolfcode.business.mapper.BpmnInfoMapper;
import cn.wolfcode.business.vo.CarPackageAuditVO;
import cn.wolfcode.business.vo.HistoryVO;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.wolfcode.common.annotation.Log;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.enums.BusinessType;
import cn.wolfcode.business.domain.CarPackageAudit;
import cn.wolfcode.business.service.ICarPackageAuditService;
import cn.wolfcode.common.utils.poi.ExcelUtil;
import cn.wolfcode.common.core.page.TableDataInfo;

/**
 * 套餐审核Controller
 *
 * @author 魏鹏程
 * @date 2023-11-03
 */
@RestController
@RequestMapping("/business/CarPackageAudit")
public class CarPackageAuditController extends BaseController {
    @Autowired
    private ICarPackageAuditService carPackageAuditService;


    /**
     * 查询套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarPackageAudit carPackageAudit) {
        startPage();
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        return getDataTable(list);
    }

    /**
     * 导出套餐审核列表
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:export')")
    @Log(title = "套餐审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarPackageAudit carPackageAudit) {
        List<CarPackageAudit> list = carPackageAuditService.selectCarPackageAuditList(carPackageAudit);
        ExcelUtil<CarPackageAudit> util = new ExcelUtil<CarPackageAudit>(CarPackageAudit.class);
        util.exportExcel(response, list, "套餐审核数据");
    }

    /**
     * 获取套餐审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(carPackageAuditService.selectCarPackageAuditById(id));
    }

    /**
     * 新增套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:add')")
    @Log(title = "套餐审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarPackageAudit carPackageAudit) {
        return toAjax(carPackageAuditService.insertCarPackageAudit(carPackageAudit));
    }

    /**
     * 修改套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:edit')")
    @Log(title = "套餐审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarPackageAudit carPackageAudit) {
        return toAjax(carPackageAuditService.updateCarPackageAudit(carPackageAudit));
    }

    /**
     * 删除套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:remove')")
    @Log(title = "套餐审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(carPackageAuditService.deleteCarPackageAuditByIds(ids));
    }

    /**
     * 查看流程图片
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:remove')")
    @Log(title = "套餐审核", businessType = BusinessType.DELETE)
    @GetMapping("/process/{id}")
    public void getprocessImg(@PathVariable("id") Long id, HttpServletResponse response) throws IOException {
        InputStream inputStream = carPackageAuditService.getprocessImg(id);
        IOUtils.copy(inputStream, response.getOutputStream());
    }

    /**
     * 撤销套餐审核
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:remove')")
    @Log(title = "套餐审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/auditCancel/{id}")
    public AjaxResult auditCancel(@PathVariable Long id) {
        carPackageAuditService.auditCancel(id);
        return AjaxResult.success();
    }

    /**
     * 套餐审核历史
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:auditHistory')")
    @GetMapping("/auditHistory/{instanceId}")
    public AjaxResult auditHistory(@PathVariable("instanceId") Long instanceId) {
        List<HistoryVO> list = carPackageAuditService.queryHistory(instanceId);
        return AjaxResult.success(list);
    }

    /**
     * 查询我的代办列表
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:todo')")
    @GetMapping("/todo")
    public TableDataInfo todo(CarPackageAudit carPackageAudit) {
        List<CarPackageAudit> list = carPackageAuditService.selectTodo(carPackageAudit);
        if (list == null) {
            return new TableDataInfo(Collections.emptyList(), 0);
        }
        return getDataTable(list);
    }

    /**
     * 审核待办
     */
    @PreAuthorize("@ss.hasPermi('business:CarPackageAudit:audit')")
    @Log(title = "套餐审核", businessType = BusinessType.INSERT)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody CarPackageAuditVO vo) {
        carPackageAuditService.audit(vo);
        return AjaxResult.success();
    }

    /**
     * 查询套餐审核列表-done
     */
    @GetMapping("/listDone")
    public TableDataInfo done(CarPackageAudit carPackageAudit) {
        List<CarPackageAudit> list = carPackageAuditService.doneQuery(carPackageAudit);
        if (list == null) {
            return new TableDataInfo(Collections.emptyList(), 0);
        } else {
            return getDataTable(list);
        }
    }
}
